// selectClassAndCompany.js
var menuIsShow = false;
var classArr = [{
					id : 0,
					classname : "全部",
					text : "全部"
				}];
var companyArr = [{
					id : 0,
					corp_name : "全部",
					text : "全部"
				}];
function prepareClassAndCompanyData(){
	loadClassArrData();
	loadCompanyArrData();
	api.addEventListener({
	    name: 'tapTrainDownMenuNotifi'
	}, function(ret, err) {
		jumpToSelectHtml(ret.value.menuType);
	    closeMenu();
	});
}
//加载班级数据
function loadClassArrData(){
	var params = {
		uid : $api.getStorage('cfnetppuid'),
		jid : $api.getStorage('cfnetppjid')
	};
	cfnetppPOST(urlClasslist, params, true, function(data, status){
		if (status == 'success') {//获取网络
			if (data.status == 1) {
				var list = data.json;
				if (list != null && list.constructor == Array && list.length > 0) {
					classArr = new Array();
					classArr.push({
						id : 0,
						classname : "全部",
						text : "全部"
					});
					for (var i = 0; i < list.length; i++) {
						var classData = list[i];
						classData["text"] = classData.classname;
						classArr.push(classData);
					}
				}
			}
		}
	});
}
//加载实习企业数据
function loadCompanyArrData(){
	var params = {
		uid: $api.getStorage('cfnetppuid'),
		jid: $api.getStorage('cfnetppjid')
	};
	cfnetppPOST(urlCompanylist, params, true, function(data, status){
		if (status == 'success') {
			if (data.status == 1) {
				var companyList = data.json;
				if (companyList != null && companyList.constructor == Array && companyList.length > 0) {
					companyArr = new Array();
					companyArr.push({
						id : 0,
						corp_name : "全部",
						text : "全部"
					});
					for (var i = 0; i < companyList.length; i++) {
						var companyData = companyList[i];
						companyData["text"] = companyData.corp_name;
						companyArr.push(companyData);
					}
				}
			}
		}
	});
}
function jumpToSelectHtml(type){
	if (type == 0) {//班级
		api.openFrame({
		    name: 'Teacher_SelectClassPicker',
		    url: 'Teacher_SelectClassPicker.html',
		    rect: {
		        x: 0,
		        y: 0,
		        w: 'auto',
		        h: 'auto'
		    },
		    pageParam: {
		        classArr: classArr
		    }
		});
		// api.setFrameAttr({
		//     name: 'Teacher_SelectClassPicker',
		//     hidden: false
		// });
	}else{
		api.openFrame({
		    name: 'Teacher_SelectCompanyPicker',
		    url: 'Teacher_SelectCompanyPicker.html',
		    rect: {
		        x: 0,
		        y: 0,
		        w: 'auto',
		        h: 'auto'
		    },
		    pageParam: {
		        companyArr: companyArr
		    }
		});
		// api.setFrameAttr({
		//     name: 'Teacher_SelectCompanyPicker',
		//     hidden: false
		// });
	}
}
function onSelectClassOrCompanyClick(){
	if (menuIsShow) {
		closeMenu();
	}else{
		openMenu();
	}
}
function openMenu(){
	api.openFrame({
	    name: 'Teacher_selectDownMenu',
	    url: 'Teacher_selectDownMenu.html',
	    rect: {
	        x: api.winWidth - 110,
	        y: 66,
	        w: 98,
	        h: 80
	    }
	});
	menuIsShow = true;
}
function closeMenu(){
	api.closeFrame({
	    name: 'Teacher_selectDownMenu'
	});
	menuIsShow = false;
}
